/*
 * Copyright (c) 2017, Li Bo/Alex All rights reserved.
 * 
 * http://blog.sina.com.cn/alex4java
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.hyts.jlogger.manager;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.util.logging.LogManager;

import com.hyts.jlogger.config.Config;
import com.hyts.jlogger.factory.LoggerFactory;
import com.hyts.jlogger.util.ReadJarUtil;
import com.hyts.jlogger.util.StringUtils;


/**
 * @ClassName: LoggerManager
 * @Description: 对总体日志jdk本身日志控件进行覆盖操作<br>
 * 				   针对于LoggerManager本身进行操作总体<br>
 * 				    配置日志的操作 属于核心部分<br>
 * @author: 李博/Alex
 * @date: 2017-3-2 下午3:20:19
 * @email:  alexlibochn@china-pui.com.cn
 */
public final class LoggerManager extends LoggerFactory{
	
	
	/*********************current file path****************************************/
	
	private static String loggingPath; 
	
	
	/**
	 * @Title: setLoggerConfigurePath
	 * @Description: setting the loggerPath
	 * @param loggerPath
	 * @return: void
	 * @throws IOException 
	 * @throws SecurityException 
	 */
	public static void setLoggerConfigurePath(String loggerPath) throws SecurityException, IOException{
		
		loggingPath = StringUtils.isNotNull(loggerPath)?loggerPath:Config.DEFAULT_LOG_CONFG_PATH;
		
		File file = new File(loggingPath);
		
		if(!file.exists()){
			new ReadJarUtil().load();
		}
		LogManager manager = LogManager.getLogManager();
		try(
			BufferedInputStream bis = new BufferedInputStream(LoggerManager.class.getClassLoader().getResourceAsStream(loggingPath));
			) {
			manager.readConfiguration(bis);
		} catch (SecurityException | IOException e) {
			System.err.println(e.getMessage());
		} 
	}
	
}
